package com.talkweb.newproject.admin.sysrolemapping.service;

import com.sun.deploy.net.proxy.PACFunctionsImpl;
import com.talkweb.newproject.admin.sysrolemapping.dao.SysRoleMappingDao;
import com.talkweb.newproject.admin.sysrolemapping.dto.SysRoleMappingDTO;
import com.talkweb.newproject.api.model.admin.SysRoleMappingParam;
import com.talkweb.newproject.common.web.annotation.Page;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by qsf on 2019/5/8.
 */
@Service
public class SysRoleMappingService implements Serializable {
    private static final long serialVersionUID=1L;

    @Autowired
    private SysRoleMappingDao sysRoleMappingDao;

    /**
     * 新增sysRoleMapping
     * @param sysRoleMappingDTO
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = {Exception.class})
    public Long insertSysRoleMapping(SysRoleMappingDTO sysRoleMappingDTO) throws Exception {
        Map<String,Object> params = new HashMap();
        params.put("dto",sysRoleMappingDTO);
        int count = sysRoleMappingDao.insertSysRoleMapping(params);
        SysRoleMappingDTO dto = (SysRoleMappingDTO) params.get("dto");
        Long id = dto.getId();
        return id;
    }

    /**
     * 更新sysRoleMapping
     * @param dto
     * @throws Exception
     */
    @Transactional(rollbackFor = {Exception.class})
    public void updateSysRoleMapping(SysRoleMappingDTO dto) throws Exception {
        Map<String,Object> params = new HashMap<>();
        params.put("dto",dto);
        sysRoleMappingDao.updateSysRoleMapping(params);
    }

    /**
     * 根据id删除sysRoleMapping
     * @param ids
     * @return
     * @throws Exception
     */
    public Boolean deleteSysRoleMapping(String ids) throws Exception {
        int count = sysRoleMappingDao.deleteSysRoleMapping(ids);
        if(count>0) {
            return true;
        }else {
            return false;
        }
    }

    /**
     * 根据id查询sysRoleMapping
     * @param id
     * @return
     */
    public SysRoleMappingDTO querySysRoleMappingByPrimaryKey(String id) throws Exception{
        SysRoleMappingDTO result = sysRoleMappingDao.querySysRoleMappingByPrimaryKey(id);
        if(result == null) {
            result = new SysRoleMappingDTO();
        }
        return result;
    }

    /**
     * 根据条件查询对象
     * @param dto
     * @return
     * @throws Exception
     */
    public SysRoleMappingDTO queryLikeSysRoleMapping(SysRoleMappingDTO dto) throws Exception {
        Map<String ,Object> params = new HashMap<>();
        params.put("dto",dto);
        return sysRoleMappingDao.queryLikeSysRoleMapping(params);

    }

    /**
     * 查询列表数据
     * @param params
     * @return
     * @throws Exception
     */
    public List<SysRoleMappingDTO> searchSysRoleMappingByPaging(Map<String,Object> params) throws Exception {
        return sysRoleMappingDao.searchSysRoleMappingByPaging(params);
    }

    @Page
    public Object searchSysRoleMapping(SysRoleMappingParam obj) throws Exception {
        Map<String,Object> params = new HashedMap();
        params.put("dto",obj);
        List<SysRoleMappingDTO> sysRoleMappingDTOList = sysRoleMappingDao.searchSysRoleMapping(params);
        return sysRoleMappingDTOList;
    }
}
